package ar.edu.unq.wannaplay.dtos;

import org.joda.time.DateTime;
import org.joda.time.Interval;

import ar.edu.unq.wannaplay.calendareable.Licence;

public class LicenceDTO extends DTO<Licence> {

    private static final long serialVersionUID = 1L;

    private String name;

    private int id;

    private Interval interval;

    public LicenceDTO() {
        super();
        // Empty constructor, entirely made for bindingConstruction on
        // presentationModel
    }

    public LicenceDTO(final Licence licence) {
        super();
        id = licence.getId();
        name = licence.getName();
        interval = licence.getInterval();
    }

    @Override
    public Licence fromDto() {
        Licence licence = new Licence(this.getName(), this.getInterval());
        licence.setId(this.getId());
        return licence;
    }

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public Interval getInterval() {
        return interval;
    }

    public void setInterval(final Interval interval) {
        this.interval = interval;
    }

    public int getId() {
        return id;
    }

    @SuppressWarnings("unused")
    private void setId(final int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        DateTime start = interval.getStart();
        DateTime end = interval.getEnd();
        return name + ", " + start.getDayOfMonth() + "/" + start.getMonthOfYear() + "/" + start.getYear() + "-"
                + +end.getDayOfMonth() + "/" + end.getMonthOfYear() + "/" + end.getYear();
    }

}
